﻿Imports DevExpress.XtraEditors
Imports DevExpress.XtraSplashScreen
Public Class DMHangHoa
    Dim HeSoQuiDoi As Decimal
    Dim LoaiDVT As String
    Dim DVT As String
    Dim TenDVT As String
    Public Overrides Sub setSubSau_TaoMoi() 'mặc định cho các control
        Me.TonkhotoidaITextEdit.EditValue = 1000
        Me.TonkhotoithieuITextEdit.EditValue = 10
        Me.CanhbaohandungITextEdit.EditValue = 3
        Me.TinhtrangISearchLookupEdit.EditValue = "1"
        Me.Quidoi1ITextEdit.EditValue = "1"
        Me.ThuevatITextEdit.EditValue = 5
    End Sub
    Private Sub LoadDuLieu()
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        Me.LoaiDVTTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.LoaiDVT)
        Me.NhomThuocTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.NhomThuoc)
        Me.LoaiThuocTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.LoaiThuoc)
        Me.DMDonViTinhTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMDonViTinh)
        Me.TinhTrangTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.TinhTrang)
        Me.DMHangHoa_DonViTinhTableAdapter.Fill(Me.PCV_CLINICDataSet.DMHangHoa_DonViTinh)
        Me.DMHangHoa_DonViTinhLonHonTableAdapter.Fill(Me.PCV_CLINICDataSet.DMHangHoa_DonViTinhLonHon)
        Me.DMHangHoaTableAdapter.Fill(Me.PCV_CLINICDataSet.DMHangHoa)
        Me.setHeaderFooter(Main.TenDoanhNghiep.ToString, Main.DiaChiDoanhNghiep.ToString)
        Me.IGridViewDs01.setTitle("DANH MỤC THUỐC")
        SplashScreenManager.CloseForm()
    End Sub
    Private Sub DMHangHoa_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        LoadDuLieu()
    End Sub
    Public Sub New()
        InitializeComponent()
        Me.setSoTabThamChieu(0)
        Me.setSoTab(2)
        Me.setObj(Me.PCV_CLINICDataSet, Me.PCV_CLINICDataSet.DMHangHoa, Me.DMHangHoaBindingSource, Me.TableAdapterManager, Me.DMHangHoaTableAdapter, Me.MaITextEdit, TinhtrangISearchLookupEdit)
        Me.setTab1(Me.PCV_CLINICDataSet.DMHangHoa_DonViTinh, Me.FKDMHangHoaDoma40F9A68CBindingSource, Me.DMHangHoa_DonViTinhTableAdapter)
        Me.setTab2(Me.PCV_CLINICDataSet.DMHangHoa_DonViTinhLonHon, Me.FKDMHangHoaDoma5DB5E0CBBindingSource, Me.DMHangHoa_DonViTinhLonHonTableAdapter)
    End Sub
    Private Sub setQuiCach() 'set lại qui cách
        If Me.getState <> 0 Then
            If IsDBNull(Me.Dvt1ISearchLookupEdit.EditValue) = False Then
                Me.QuicachITextEdit.EditValue = Me.Quidoi1ITextEdit.EditValue & " " & Me.Dvt1ISearchLookupEdit.Text
            End If
            If IsDBNull(Me.Dvt2ISearchLookupEdit.EditValue) = False Then
                Me.QuicachITextEdit.EditValue = Me.Quidoi1ITextEdit.EditValue & " " & Me.Dvt1ISearchLookupEdit.Text & "/ " & Me.Quidoi2ITextEdit.EditValue & " " & Me.Dvt2ISearchLookupEdit.Text
            End If
            If IsDBNull(Me.Dvt3ISearchLookupEdit.EditValue) = False Then
                Me.QuicachITextEdit.EditValue = Me.Quidoi1ITextEdit.EditValue & " " & Me.Dvt1ISearchLookupEdit.Text & "/ " & Me.Quidoi2ITextEdit.EditValue & " " & Me.Dvt2ISearchLookupEdit.Text & "/ " & Me.Quidoi3ITextEdit.EditValue & " " & Me.Dvt3ISearchLookupEdit.Text
            End If
            If IsDBNull(Me.Dvt4ISearchLookupEdit.EditValue) = False Then
                Me.QuicachITextEdit.EditValue = Me.Quidoi1ITextEdit.EditValue & " " & Me.Dvt1ISearchLookupEdit.Text & "/ " & Me.Quidoi2ITextEdit.EditValue & " " & Me.Dvt2ISearchLookupEdit.Text & "/ " & Me.Quidoi3ITextEdit.EditValue & " " & Me.Dvt3ISearchLookupEdit.Text & "/ " & Me.Quidoi4ITextEdit.EditValue & " " & Me.Dvt4ISearchLookupEdit.Text
            End If
        End If
    End Sub
    Private Sub DonvitinhISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles DonvitinhISearchLookupEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Dvt1ISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Dvt1ISearchLookupEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Dvt2ISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Dvt2ISearchLookupEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Dvt3ISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Dvt3ISearchLookupEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Dvt4ISearchLookupEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Dvt4ISearchLookupEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub IGridViewChiTiet01_InitNewRow(sender As System.Object, e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridViewChiTiet01.InitNewRow
        Me.IGridViewChiTiet01.SetFocusedRowCellValue("heso", 0)
        Me.IGridViewChiTiet01.SetFocusedRowCellValue("dvt", Me.DVT)
        Me.IGridViewChiTiet01.SetFocusedRowCellValue("tendvt", Me.TenDVT)
        Me.IGridViewChiTiet01.SetFocusedRowCellValue("uid", System.Guid.NewGuid)
        Me.IGridViewChiTiet01.SetFocusedRowCellValue("dvtmacdinh", Me.DonvitinhISearchLookupEdit.Text)
    End Sub
    Private Sub RepositoryItemSearchLookUpEdit_DMDonViTinh_EditValueChanging(sender As Object, e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit_DMDonViTinh.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        IGridViewChiTiet01.SetFocusedRowCellValue("dvt", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
        IGridViewChiTiet01.SetFocusedRowCellValue("tendvt", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
    End Sub
    Private Sub Quidoi1ITextEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Quidoi1ITextEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Quidoi2ITextEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Quidoi2ITextEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Quidoi3ITextEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Quidoi3ITextEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub Quidoi4ITextEdit_EditValueChanged(sender As Object, e As EventArgs) Handles Quidoi4ITextEdit.EditValueChanged
        setQuiCach()
    End Sub
    Private Sub RepositoryItemISearchLookUpEdit_DMDonViTinh1_EditValueChanging(sender As Object, e As Controls.ChangingEventArgs) Handles RepositoryItemISearchLookUpEdit_DMDonViTinh1.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        IGridViewChiTiet02.SetFocusedRowCellValue("dvt", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
        IGridViewChiTiet02.SetFocusedRowCellValue("tendvt", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
    End Sub

    Private Sub IGridViewChiTiet02_InitNewRow(sender As Object, e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridViewChiTiet02.InitNewRow
        Me.IGridViewChiTiet02.SetFocusedRowCellValue("heso", 0)
        Me.IGridViewChiTiet02.SetFocusedRowCellValue("dvt", Me.DVT)
        Me.IGridViewChiTiet02.SetFocusedRowCellValue("tendvt", Me.TenDVT)
        Me.IGridViewChiTiet02.SetFocusedRowCellValue("uid", System.Guid.NewGuid)
        Me.IGridViewChiTiet02.SetFocusedRowCellValue("dvtmacdinh", Me.DonvitinhISearchLookupEdit.Text)
    End Sub
End Class
